﻿using AutoMapper;
using Pay.DTO;
using Pay.Data;
using Pay.IService;
using Pay.Core;

namespace Pay.Service.AutoMapper {
    public class MerchantCertificationMapper : IStartupDto {
        private IMapperConfigurationExpression _cfg;
        public MerchantCertificationMapper(IMapperConfigurationExpression cfg) {
            _cfg = cfg;
        }
        public void Execute() {
            Create();
        }
        protected virtual void Create() {
            _cfg.CreateMap<merchant_certification_dto, MerchantCertification>()
                .ForMember(dest => dest.Id, src => src.MapFrom(c => c.id))
                .ForMember(dest => dest.CertificationsNum, src => src.MapFrom(c => c.certifications_num))
                .ForMember(dest => dest.FilingNum, src => src.MapFrom(c => c.filing_num))
                .ForMember(dest => dest.UnCertificationsNum, src => src.MapFrom(c => c.un_certifications_num))
                .ForMember(dest => dest.UnFilingNum, src => src.MapFrom(c => c.un_filing_num))
                .ForMember(dest => dest.CertificationTime, src => src.MapFrom(c => c.certification_time.ToUnix()))
                .ForMember(dest => dest.FilingTime, src => src.MapFrom(c => c.filing_time.ToUnix()));

            _cfg.CreateMap<MerchantCertification, merchant_certification_dto>()
                .ForMember(dest => dest.id, src => src.MapFrom(c => c.Id))
                .ForMember(dest => dest.certifications_num, src => src.MapFrom(c => c.CertificationsNum))
                .ForMember(dest => dest.filing_num, src => src.MapFrom(c => c.FilingNum))
                .ForMember(dest => dest.un_certifications_num, src => src.MapFrom(c => c.UnCertificationsNum))
                .ForMember(dest => dest.un_filing_num, src => src.MapFrom(c => c.UnFilingNum))
                .ForMember(dest => dest.certification_time, src => src.MapFrom(c => c.CertificationTime.ToDateTime()))
                .ForMember(dest => dest.filing_time, src => src.MapFrom(c => c.FilingTime.ToDateTime()));
        }
    }
}
